{extend name="base"/}
{block name="css"}
<link rel="stylesheet" href="__ADMIN__/css/goods_order.css">
<style>
        .layui-body {
            position: absolute;
            left: 120px;
            right: 0;
            top: 20px;
            bottom: 0;
            z-index: 998;
            width: auto;
            overflow: hidden;
            overflow-y: auto;
            box-sizing: border-box;
        }
    </style>
{/block}
{block name="content"}

<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg12">
            <fieldset class="layui-elem-field">
                <legend>编辑商品</legend>
                <div class="layui-field-box">
                    <form id="myForm" class="layui-form" enctype="multipart/form-data">
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="name" value="{$info.name}" lay-verify="required"  placeholder="请输入">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">所属分类</label>
                            <div class="layui-input-block">
                                <select name="cat_id" id="" class="con" >
                                    <option value="0">{:lang('请选择商品类型')}</option>
                                    {volist name='selectOption' id='vo'}
                                    <option value="{$vo.cat_id}" {if $info.cat_id eq $vo.cat_id}selected = "selected" {/if}>{$vo.cat_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品原价</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="original_price" value="{$info.original_price}"  lay-verify="required" placeholder="请输入">
                
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品平台价</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="sale_price" value="{$info.sale_price}" lay-verify=""  placeholder="请输入">
                
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品拼团价</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="fighting_price" value="{$info.fighting_price}"   placeholder="请输入">

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品秒杀价</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="price_spike" value="{$info.price_spike}" lay-verify=""  placeholder="请输入">

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">库存数量</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="amount" value="{$info.amount}" lay-verify=""  placeholder="请输入">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">拼团人数（拼团商品填写）</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="people_count" {if condition = "$info.people_count > 0"}value="{$info.people_count}"{/if} lay-verify=""  placeholder="拼团商品填写">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">地标</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="landmark" value="{$info.landmark}" lay-verify=""  placeholder="请输入">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">标签（用逗号隔开）</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="label" value="{$info.label}" lay-verify=""  placeholder="如：尾单秒杀，限时秒杀，拼团秒杀">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品描述</label>
                            <div class="layui-input-block">
                                <textarea class="layui-textarea" id="LAY_demo1" style="display: none" name="detail">{$info.detail}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" >商品海报</label>
                            <button type="button" class="layui-btn layui-btn-primary pull-left" style="text-align: center;line-height: 38px;border: none; background: #009688; color: #fff;" id="slide-pc1">{:lang('选择图片')}</button>
                            <div class="pic-more">
                                <ul class="pic-more-upload-list" id="slide-pc-priview1">
                                    <li class="item_img" style="position: relative;">
                                        <div class="operate" style="position: absolute; width: 20px; height: 20px; left: 178px;top: 5px;">
                                        </div>
                                        <img src="{$info['poster']}" class="img" style="width: 200px; height: 200px;    margin-left: 100px;">
                                        <input type="hidden" class="shopimg" name="poster" value="{$info['poster']}">
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="layui-form-item" id="pics">
                        <label class="layui-form-label">商品照片(图片上传大小为750)</label>
                           <div class="layui-input-block" style="width: 100%;">
                              <div class="layui-upload">
                                 <button type="button" class="layui-btn layui-btn-primary pull-left" style="text-align: center;line-height: 38px;border: none; background: #009688; color: #fff;" id="slide-pc">{:lang('选择图片')}</button>
                                 <div class="pic-more">
                                    <ul class="pic-more-upload-list" id="slide-pc-priview">
                                      {if $info.img1}
                                        {volist name='info.img1' id='row'}
                                          <li class="item_img" style="position: relative;">
                                            <div class="operate" style="position: absolute; width: 20px; height: 20px; left: 178px;top: 5px;">
                                                <i class="close layui-icon"></i>
                                            </div>
                                            <img src="{$row}" class="img" style="width: 200px; height: 200px;">
                                            <input type="hidden" class="shopimg" name="pc_src[]" value="{$row}">
                                          </li>
                                        {/volist}
                                      {/if}
                                    </ul>
                                 </div>
                              </div>
                           </div>
                        </div>
                        <div style="margin-bottom: 50px;">
                            <div class="layui-inline">
                                <label class="layui-form-label">游玩开始日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="youwan_time" name="play_start_time" value="{:date('Y-m-d H:i:s',$info.play_start_time)}" placeholder="游玩开始日期">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">游玩结束日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="youwan_time1"  name="play_end_time" value="{:date('Y-m-d H:i:s',$info.play_end_time)}" placeholder="游玩结束日期">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">拼团时间限制（秒数）</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input"  name="fight_time"  value="{$info.fight_time}" style="width: 40%;">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">秒杀开始时间</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" id="time1" name="start_time" {if condition = "$info.start_time != 0"}value="{:date('Y-m-d H:i:s',$info.start_time)}"{/if} style="width: 40%;">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">秒杀结束时间</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" id="time2" name="end_time" {if condition = "$info.end_time != 0"}value="{:date('Y-m-d H:i:s',$info.end_time)}"{/if} style="width: 40%;">
                            </div>
                        </div>
                        <div class="layui-form-item">
                                <label class="layui-form-label">是否首页推荐</label>
                                <div class="layui-input-block">
                                    <select name="is_home" >
                                        <option value="0" {if condition= "$info.is_home eq '0'"} selected {/if}>否</option>
                                        <option value="1" {if condition= "$info.is_home eq '1'"} selected {/if}>是</option>
                                        
                                    </select>
                                </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否上架</label>
                            <div class="layui-input-block">
                                <select name="is_on" >
                                    <option value="0" {if condition= "$info.is_on eq '否'"} selected {/if}>下架</option>
                                    <option value="1" {if condition= "$info.is_on eq '是'"} selected {/if}>上架</option>

                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序值</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input dataIntegral" name="sort" value="{$info.sort}" lay-verify=""  placeholder="请输入">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id" value="{$info.id}"/>
                                 <input type="button"  lay-submit="" lay-filter="addAbout" style="width: 100px;height: 45px;text-align: center;line-height: 45px;border: none; background: #009688; color: #fff;border-radius: 2px;" value="{:lang('确认保存')}" class="" id="submit">
                            </div>
                        </div>

                    </form>
                </div>
            </fieldset>
        </div>
    </div>
</div>




{/block}
{block name="js"}
<script type="text/javascript" src="__SHOP__/js/jquery.form.js"></script>
<script type="text/javascript" src="__SHOP__/js/swiper.min.js"></script>
<script type="text/javascript" src="__SHOP__/js/layui/layui.js"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#time1' //指定元素
            ,type:'datetime'
        });
        //年月选择器
        laydate.render({
            elem: '#youwan_time'
            ,type: 'datetime'
        });
        //年月选择器
        laydate.render({
            elem: '#youwan_time1'
            ,type: 'datetime'
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#time2' //指定元素
            ,type:'datetime'
        });
    });
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        var time1 = laydate.render({
            elem: '#fromTime', //指定元素
            type: 'time',
            lang: 'en',
            value: '09:00:00'
        });
        var time2 = laydate.render({
            elem: '#toTime',
            type: 'time',
            lang: 'en',
            value: '20:00:00'
        })
    });
</script>
<script>
    $(function () {
        layui.config({
            base: "/static/backend/js/"
        }).use(['form', 'layer', 'jquery', 'layedit', 'upload'], function () {
            var form = layui.form,
                    layer = parent.layer === undefined ? layui.layer : parent.layer,
                    upload = layui.upload,
                    layedit = layui.layedit,
                    $ = layui.jquery;
            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo1', {
                uploadImage: {
                    url: '/backend/goods/uploadImg/'
                    ,type: 'post'
                }
            });
            form.on("submit(addAbout)", function (data) {
                data.field.content = layedit.getContent(editIndex);

                var formdom = $('#myForm')[0]
                        ,formdata = new FormData(formdom);
                formdata.append('content', layedit.getContent(editIndex));
                $.ajax({
                    url: '/backend/goods/dodetail',
                    type: 'POST',
                    data: formdata,
                    processData: false, // jQuery不要去处理发送的数据
                    contentType: false, // jQuery不要去设置Content-Type请求头
                    success: function(res) {
                        console.log(res);
                        if(res.code==1){
                            layer.msg(res.msg, {
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                setTimeout(parent.location.reload(),3000);
                            });
                            //刷新父页面

                        }else{
                            top.layer.msg(res.msg);
                        }
                    }

                });


                return false;
            })

        });
        $('.getimg').change(function () {
            var $imgShow = $(this).parents('.img-box').find('.show_img');
            // //console.log($imgShow)
            var reader = new FileReader();
            reader.onload = function (e) {
                $imgShow.attr("src", e.target.result)
            }
            reader.readAsDataURL(this.files[0]);
        });
    })
</script>
<script>
    layui.use('upload', function () {
        var $ = layui.jquery;
        var upload = layui.upload;
        upload.render({
            elem: '#slide-pc1',
            url: "/backend/goods/upload_img",
            size: 10000,
            type: "post",
            exts: 'jpg|png|jpeg',
            multiple: true,
            number: 9,
            before: function (obj) {
                layer.msg('图片上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            },
            done: function (res) {
                console.log(res);
                layer.close(layer.msg()); //关闭上传提示窗口
                if (res.status == 0) {
                    return layer.msg(res.message);
                }
                $('#slide-pc-priview1').html(
                        '<li class="item_img" style="position: relative;"><div class="operate" style="position: absolute; width: 20px; height: 20px; left: 178px;top: 5px;"></div><img src="' +
                        res.filepath +
                        '" class="img" style="width: 200px; height: 200px;margin-left:109px;"><input type="hidden" class="shopimg" name="poster" value="' +
                        res.filepath + '" /></li>');
            }
        });
    });
    layui.use('upload', function () {
        var $ = layui.jquery;
        var upload = layui.upload;
        upload.render({
            elem: '#slide-pc',
            url: "/backend/goods/upload_img",
            size: 10000,
            type: "post",
            exts: 'jpg|png|jpeg',
            multiple: true,
            number: 9,
            before: function (obj) {
                layer.msg('图片上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            },
            done: function (res) {
                
                console.log(res);
                layer.close(layer.msg()); //关闭上传提示窗口
                if (res.status == 0) {
                    return layer.msg(res.message);
                }
                $('#slide-pc-priview').append(
                        '<li class="item_img" style="position: relative;"><div class="operate"  style="position: absolute; width: 20px; height: 20px; left: 178px;top: 5px;"><i  class="close layui-icon"></i></div><img src="' +
                        res.filepath +
                        '" class="img" style="width: 200px; height: 200px;"><input type="hidden" class="shopimg" name="pc_src[]" value="' +
                        res.filepath + '" /></li>');
            }
        });
    });
    //点击多图上传的X,删除当前的图片
    $("body").on("click", ".close", function () {
        var id = $("input[name='id']").val();
        var path = $(this).parent().siblings('.img').attr('src');
        $.post('/backend/goods/del_img',{'id':id,path:path},function(data){
            if(data.status == 1){
                layer.msg(data.msg, {
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){
                    location.reload();
                });
            }else{
                layer.msg(data.msg);
            }
        })
        $(this).closest("li").remove();
    });
    $("body").on("click", ".pic-more ul li .toright", function () {
        var li_index = $(this).closest("li").index();
        $(this).closest("li").insertAfter($(this).closest("ul").find("li").eq(Number(li_index) + 1));
    });
</script>
{/block}